<%@ CODEPAGE=65001 %>
<% Option Explicit %>
<% On Error Resume Next %>
<% Response.Charset="UTF-8" %>
<% Response.Buffer=True %>
<!-- #include file="c_option.asp" -->
<!-- #include file="c_function.asp" -->
<!-- #include file="c_system_lib.asp" -->
<!-- #include file="c_system_base.asp" -->
<%

If Request.ServerVariables("REQUEST_METHOD")="POST" Then
  
  Dim str, Conn, Rs, objStream

  Set Conn = Server.CreateObject("ADODB.Connection")
  Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & BlogPath & "/" & ZC_DATABASE_PATH

  str = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbcrlf
  str = str & "<urlset xmlns=""http://www.google.com/schemas/sitemap/0.84""" & vbcrlf
  str = str & "xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" & vbcrlf
  str = str & "xsi:schemaLocation=""http://www.google.com/schemas/sitemap/0.84" & vbcrlf
  str = str & "http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"">" & vbcrlf
  str = str & "<url>" & vbcrlf
  str = str & "<loc>" & ZC_BLOG_HOST & "</loc>" & vbcrlf
  str = str & "<lastmod>" & FormatDate("YYYY-MM-DD",Date()) & "</lastmod>" & vbcrlf
  str = str & "<changefreq>always</changefreq>" & vbcrlf
  str = str & "<priority>1.0</priority>" & vbcrlf
  str = str & "</url>" & vbcrlf
  Set Rs = Conn.Execute("select * from blog_Article where log_Level=4 order by log_PostTime desc")
  Do While Not Rs.Eof
    str = str & "<url>" & vbcrlf
    str = str & "<loc>" & ZC_BLOG_HOST & "post/" & Rs("log_ID") & "." & ZC_STATIC_TYPE & "</loc>" & vbcrlf
    str = str & "<lastmod>" & FormatDate("YYYY-MM-DD", Rs("log_PostTime")) & "</lastmod>" & vbcrlf
    str = str & "<changefreq>daily</changefreq>" & vbcrlf
    str = str & "<priority>0.8</priority>" & vbcrlf
    str = str & "</url>" & vbcrlf
    Rs.MoveNext
  Loop
  Rs.Close
  Set Rs = Nothing
  Set Conn = Nothing
  str = str & "</urlset>"

  Set objStream = Server.CreateObject("ADODB.Stream")
    With objStream
    .Type = adTypeText
    .Mode = adModeReadWrite
    .Open
    .Charset = "utf-8"
    .Position = objStream.Size
    .WriteText=str
    .SaveToFile BlogPath & "/googlesitemap.xml",adSaveCreateOverWrite
    .Close
    End With

  Set objStream = Nothing
  If Not Err Then
    Response.Write("<script>alert('成功生成站点地图!');history.back();</script>")
    Response.End
  End If
End If

Function FormatDate(FormatStr, CurDateTime)
  Dim sTemp,YYYY,YY,MM,DD,HH,mmm,SS
  sTemp = FormatStr
  If IsDate(CurDateTime) Then
    YYYY = Year(CurDateTime)
    YY = Mid(Year(CurDateTime),3,2)
    MM = Month(CurDateTime)
    If CInt(MM) < 10 Then MM = "0"&MM
    DD  = Day(CurDateTime)
    If CInt(DD) < 10 Then DD = "0"&DD
    HH = Hour(CurDateTime)
    If CInt(HH) < 10 Then HH = "0"&DD
    mmm = Minute(CurDateTime)+1
    If CInt(mmm) < 10 Then mmm = "0"&mmm
    SS = Second(CurDateTime)
    If CInt(SS) < 10 Then SS = "0"&SS
    sTemp = Replace(Replace(Replace(Replace(Replace(Replace(Replace(sTemp,"YYYY",YYYY),"YY",YY),"MM",MM),"DD",DD),"HH",HH),"mm",mmm),"SS",SS)
  End If
  If IsDate(sTemp) Then 
    FormatDate = sTemp
  Else 
    FormatDate = CurDateTime
  End If
End Function
%>
<form method=post action="">
<input type="submit" value="生成站点地图">
</form>